<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<script type="text/javascript" charset="UTF-8">
	$(function() {
		$('#menuGrid').treegrid({
			url : ctx+'/sys/menu/list.htm',
			toolbar : '#menuToolbar',
			title : '菜单',
			iconCls : 'icon-save',
			rownumbers: true,
			animate:true,
			//collapsible:true,
			fitColumns:true,
			height:450,
			idField : 'm_id',
			treeField:'m_name',
			columns : [ [
			{
				field : 'm_name',
				title : '名称',
				width : 150
			},
			{
				field : 'url',
				title : '链接',
				width : 200
			},
			{
				field : 'state_',
				title : '状态',
				width : 50
			},
			{
				field : 'order_by',
				title : '序号',
				width : 50
			}
			] ],
			onDblClickCell: function(index,field,value){
				var node = $('#menuGrid').treegrid('getSelected');
				openMenuDialog(node.m_id);
			}
		});

	});
	function openMenuDialog(id) {
		var title="菜单新增";
		var href=ctx+'/jsp/sys/menu.jsp?id='+id;
		if(id.length>0){
			title="菜单修改";
		}
		$('<div/>').dialog({
			href : href ,
			width : 460,
			height : 200,
			modal : true,
			title : title,
			buttons : [{
				text : '保存',
				handler : function() {
					var d = $(this).closest('.window-body');
					var data=JSON.stringify($('#menuForm').form("serialize"));
					$("#menuForm input[name=data]").val(data);
					$('#menuForm').form('submit', {
						url : ctx+'/sys/menu/save.htm',
						success : function(result){
							result = JSON.parse(result);
							$.messager.show({
								msg : result.r?"操作成功":"操作失败",
								title : "提示"
							});
							$('#menuGrid').treegrid('reload');
							d.dialog('destroy');
						}
					});
				}
			},
			{
				text : '取消',
				handler : function(){
					$(this).closest('.window-body').dialog('destroy');
				}
			}],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}
	function append() {
		openMenuDialog("");
	}

	function edit() {
		var node = $('#menuGrid').treegrid('getSelected');
		if (node){
			openMenuDialog(node.m_id);
		}else{
			$.messager.show({
				msg : '请选择一条记录进行操作',
				title : '提示'
			});
		}
	}
	
	function remove() {
		
		var node = $('#menuGrid').treegrid('getSelected');
		if (node){
			$.messager.confirm('删除', '确定删除该菜单，删除后子菜单也同步删除?', function(r){
				if (r){
					$.ajax({
						url : ctx+'/sys/menu/del.htm',
						data : {
							id : node.m_id
						},
						cache : false,
						success : function(response) {
							$('#menuGrid').treegrid('unselectAll');
							$('#menuGrid').treegrid('reload');
							$.messager.show({
								title : '提示',
								msg : '删除成功！'
							});
						}
					});
				}
			});
			
		}else{
			$.messager.show({
				msg : '请选择一条记录进行操作',
				title : '提示'
			});
		}
	}

	function searchFun() {
		$.post(ctx+'/sys/menu/list.htm',
				{state : $('#menuToolbar input[name=state]').val()},
				function(data){
					$('#menuGrid').treegrid('loadData',data);
					}
				,'json');
	}
	function clearFun() {
		$('#menuToolbar input').val('');
		$('#menuGrid').treegrid('load', {});
	}
</script>
</head>
 
<div id="menuToolbar" class="treegrid-toolbar" style="height: auto;">
	<fieldset>
		<legend>筛选</legend>
		<table class="tableForm">
			 
			<tr> <th>状态</th>
				<td><select id="state" name="state" style="width: 156px;" class="easyui-combobox"  
                      	data-options="editable:false,valueField:'code',textField:'code_desc',url:ctx+'/sys/paramGroup/getParam.htm?info=OS4cqbVroP&info=comm&info=state'"></select>
					<a class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="searchFun();" href="javascript:void(0);">查找</a>
					<a class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="clearFun();" href="javascript:void(0);">清空</a>
				</td>
			</tr>
		 
		</table>
	</fieldset>
	<div>
		<a class="easyui-linkbutton" iconCls="icon-add" onclick="append();" plain="true" href="javascript:void(0);">增加</a>
		<a class="easyui-linkbutton" iconCls="icon-remove" onclick="remove();" plain="true" href="javascript:void(0);">删除</a> 
		<a class="easyui-linkbutton" iconCls="icon-edit" onclick="edit();" plain="true" href="javascript:void(0);">编辑</a>
		<a class="easyui-linkbutton" iconCls="icon-undo" onclick="$('#menuGrid').treegrid('unselectAll');" plain="true" href="javascript:void(0);">取消选中</a>
	</div>
</div>
<table id="menuGrid"></table>
 
		
 